package file

import (
	"fmt"
	"os"
)

// CreateFile in any case create file
func CreateFile(fileName string) {
	f, err := os.Create(fileName)
	defer f.Close()
	if err != nil {
		fmt.Printf("CreateFile err is %v\n", err)
	}
}

// AppendText append text
func AppendText(fileName string, text string) {
	f, err := os.OpenFile(fileName, os.O_APPEND, os.ModePerm)
	defer f.Close()
	if err != nil {
		fmt.Printf("CreateFile err is %v\n", err)
	}
	f.WriteString(fmt.Sprintf("\n%s", text))
}

// AppendText2 append text
func AppendText2(fileName string, text string) {
	f, err := os.OpenFile(fileName, os.O_WRONLY, 0644)
	defer f.Close()
	if err != nil {
		fmt.Printf("CreateFile err is %v\n", err)
	}
	n, _ := f.Seek(0, 2)
	_, err = f.WriteAt([]byte(fmt.Sprintf("\n%s", text)), n)
	if err != nil {
		fmt.Printf("CreateFile err is %v\n", err)
	}
}
